package com.piotrovski.myLog;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.apache.commons.lang3.StringUtils;

/**
 * Backing bean for MyLog.
 * 
 * @author piotrek
 */
@ManagedBean
@SessionScoped
public class MyLogBean implements Serializable {

	/**
	 * Default serialVersionUID
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * The current log entry.
	 */
	private String logEntry;

	/**
	 * List of log entries.
	 */
	private LinkedList<Log> logsList;

	/**
	 * The default constructor.
	 */
	public MyLogBean() {
		logsList = new LinkedList<Log>();
	}

	/**
	 * Add log to list of logs.
	 * 
	 * @return action.
	 */
	public String addLog() {
		this.logsList.addFirst(new Log(logEntry));
		logEntry = "";
		return null;
	}

	/**
	 * Get current log entry.
	 * 
	 * @return current log entry.
	 */
	public String getLogEntry() {
		return logEntry;
	}

	/**
	 * Getter for list of logs.
	 * 
	 * @return list of logs
	 */
	public List<Log> getLogsList() {
		return logsList;
	}

	/**
	 * Check if submit button has to be disable.
	 * This condition is evaluated depending on content of current log entry.
	 * 
	 * @return true if button has to be disabled otherwise false.
	 */
	public boolean isSubmitBttnDisabled() {
		return StringUtils.isBlank(logEntry);
	}

	/**
	 * Set current log entry.
	 * 
	 * @param logEntry current log entry.
	 */
	public void setLogEntry(String logEntry) {
		this.logEntry = logEntry;
	}

}
